home *** CD-ROM | disk | FTP | other *** search
/ Young Minds / Young Minds Interactive CD-ROM.ISO / umoria / files.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-07-28  |  25.4 KB  |  809 lines

  1. #include <stdio.h>
  2.  
  3. #include "constants.h"
  4. #include "config.h"
  5. #include "types.h"
  6. #include "externs.h"
  7.  
  8. #ifdef USG
  9. #include <string.h>
  10. #include <fcntl.h>
  11. #else
  12. #include <strings.h>
  13. #include <sys/file.h>
  14. #endif
  15.  
  16. #ifdef sun   /* correct SUN stupidity in the stdio.h file */
  17. char *sprintf();
  18. #endif
  19.  
  20. #if defined(ultrix) || defined(USG)
  21. void exit();
  22. #endif
  23.  
  24. /*
  25.  *  init_scorefile
  26.  *  Open the score file while we still have the setuid privileges.  Later
  27.  *  when the score is being written out, you must be sure to flock the file
  28.  *  so we don't have multiple people trying to write to it at the same time.
  29.  *  Craig Norborg (doc)        Mon Aug 10 16:41:59 EST 1987
  30.  */
  31. init_scorefile()
  32. {
  33.   if (1 > (highscore_fd = open(MORIA_TOP, O_RDWR | O_CREAT, 0644)))
  34.     {
  35.       (void) fputs("Can't open score file!\n", stderr);
  36.       exit(1);
  37.     }
  38. }
  39.  
  40. /* Attempt to open the intro file            -RAK-     */
  41. /* This routine also checks the hours file vs. what time it is    -Doc */
  42. intro(finam)
  43. char *finam;
  44. {
  45.   register int xpos, i;
  46.   vtype in_line;
  47.   FILE *file1;
  48.   register char *string;
  49.  
  50.   /* Attempt to read hours.dat.  If it does not exist,     */
  51.   /* inform the user so he can tell the wizard about it     */
  52.   if ((file1 = fopen(MORIA_HOU, "r")) != NULL)
  53.     {
  54.       while (fgets(in_line, 80, file1) != NULL)
  55.     if (strlen(in_line) > 3)
  56.       {
  57.         if (!strncmp(in_line, "SUN:", 4))
  58.           (void) strcpy(days[0], in_line);
  59.         else if (!strncmp(in_line, "MON:", 4))
  60.           (void) strcpy(days[1], in_line);
  61.         else if (!strncmp(in_line, "TUE:", 4))
  62.           (void) strcpy(days[2], in_line);
  63.         else if (!strncmp(in_line, "WED:", 4))
  64.           (void) strcpy(days[3], in_line);
  65.         else if (!strncmp(in_line, "THU:", 4))
  66.           (void) strcpy(days[4], in_line);
  67.         else if (!strncmp(in_line, "FRI:", 4))
  68.           (void) strcpy(days[5], in_line);
  69.         else if (!strncmp(in_line, "SAT:", 4))
  70.           (void) strcpy(days[6], in_line);
  71.       }
  72.       (void) fclose(file1);
  73.     }
  74.   else
  75.     {
  76.       (void) fprintf(stderr, "There is no hours file.\nPlease inform the wizard, %s, so he can correct this!\n", WIZARD);
  77.       exit_game();
  78.     }
  79.  
  80.   /* Check the hours, if closed  require password     */
  81.   string = index(finam, '^');
  82.   if (string)
  83.     xpos = strlen(finam) - strlen(string);
  84.   else
  85.     xpos = -1;
  86.   if (xpos >= 0)
  87.     if (check_pswd())
  88.       insert_str(finam, "^", "");
  89.   if (!check_time())
  90.     {
  91.       if (!wizard1)
  92.     {
  93.       if ((file1 = fopen(MORIA_HOU, "r")) != NULL)
  94.         {
  95.           clear_screen(0, 0);
  96.           for (i = 0; fgets(in_line, 80, file1) != NULL; i++)
  97.         prt(in_line, i, 0);
  98.           (void) fclose(file1);
  99.         }
  100.       exit_game();
  101.     }
  102.     }
  103.  
  104.   /* Print the introduction message, news, ect...         */
  105.   if ((file1 = fopen(MORIA_MOR, "r")) != NULL)
  106.     {
  107.       clear_screen(0, 0);
  108.       for (i = 0; fgets(in_line, 80, file1) != NULL; i++)
  109.     prt(in_line, i, 0);
  110.       pause_line(23);
  111.       (void) fclose(file1);
  112.     }
  113. }
  114.  
  115.  
  116. /* Prints dungeon map to external file            -RAK-     */
  117. print_map()
  118. {
  119.   register int i, j, m, n;
  120.   register k, l;
  121.   register i7, i8;
  122.   char dun_line[MAX_WIDTH];
  123.   char *dun_ptr;
  124.   vtype filename1;
  125.   char tmp_str[80];
  126.   FILE *file1;
  127.   int page_width = OUTPAGE_WIDTH;
  128.   int page_height = OUTPAGE_HEIGHT;
  129.  
  130.   /* this allows us to strcat each character in the inner loop,
  131.      instead of using the expensive sprintf */
  132.   prt("File name: ", 0, 0);
  133.   if (get_string(filename1, 0, 11, 64))
  134.     {
  135.       if (strlen(filename1) == 0)
  136.     (void) strcpy(filename1, "MORIAMAP.DAT");
  137.       if ((file1 = fopen(filename1, "w")) == NULL)
  138.     {
  139.       (void) sprintf(dun_line, "Cannot open file %s", filename1);
  140.       prt(dun_line, 0, 0);
  141.       put_qio();
  142.       return;
  143.     }
  144.       (void) sprintf(tmp_str, "section width (default = %d char):", page_width);
  145.       prt(tmp_str, 0, 0);
  146.       (void) get_string(tmp_str, 0, strlen(tmp_str), 10);
  147.       (void) sscanf(tmp_str, "%d", &page_width);
  148.       if (page_width < 10)
  149.     page_width = 10;
  150.  
  151.       (void) sprintf(tmp_str, "section height (default = %d lines):", page_height);
  152.       prt(tmp_str, 0, 0);
  153.       (void) get_string(tmp_str, 0, strlen(tmp_str), 10);
  154.       (void) sscanf(tmp_str, "%d", &page_height);
  155.       if (page_height < 10)
  156.     page_height = 10;
  157.  
  158.       prt("Writing Moria Dungeon Map...", 0, 0);
  159.       put_qio();
  160.  
  161.       i = 0;
  162.       i7 = 0;
  163.       do
  164.     {
  165.       j = 0;
  166.       k = i + page_height - 1;
  167.       if (k >= cur_height)
  168.         k = cur_height - 1;
  169.       i7++;
  170.       i8 = 0;
  171.       do
  172.         {
  173.           l = j + page_width - 1;
  174.           if (l >= cur_width)
  175.         l = cur_width - 1;
  176.           i8++;
  177.           (void) fprintf(file1, "%c\n", 12);
  178.           (void) fprintf(file1, "Section[%d,%d];     ", i7, i8);
  179.           (void) fprintf(file1, "Depth : %d (feet)\n\n   ",
  180.                  (dun_level * 50));
  181.           for (m = j; m <= l; m++)
  182.         {
  183.           n = (m / 100);
  184.           (void) fprintf(file1, "%d", n);
  185.         }
  186.           (void) fputs("\n   ", file1);
  187.           for (m = j; m <= l; m++)
  188.         {
  189.           n = (m / 10) - (m / 100) * 10;
  190.           (void) fprintf(file1, "%d", n);
  191.         }
  192.           (void) fputs("\n   ", file1);
  193.           for (m = j; m <= l; m++)
  194.         {
  195.           n = m - (m / 10) * 10;
  196.           (void) fprintf(file1, "%d", n);
  197.         }
  198.           (void) fprintf(file1, "\n");
  199.           for (m = i; m <= k; m++)
  200.         {
  201.           (void) sprintf(dun_line, "%2d ", m);
  202.           dun_ptr = &dun_line[3];
  203.           for (n = j; n <= l; n++)
  204.             {
  205.               if (test_light(m, n))
  206.             loc_symbol(m, n, dun_ptr++);
  207.               else
  208.             *dun_ptr++ = ' ';
  209.             }
  210.           *dun_ptr++ = '\n';
  211.           (void) fputs(dun_line, file1);
  212.         }
  213.           j += page_width;
  214.         }
  215.       while (j < cur_width);
  216.       i += page_height;
  217.     }
  218.       while (i < cur_height);
  219.       (void) fclose(file1);
  220.       prt("Completed.", 0, 0);
  221.     }
  222. }
  223.  
  224.  
  225. /* Prints a list of random objects to a file.  Note that -RAK-     */
  226. /* the objects produced is a sampling of objects which           */
  227. /* be expected to appear on that level.                          */
  228. print_objects()
  229. {
  230.   register int i;
  231.   int nobj, j, level;
  232.   vtype filename1, tmp_str;
  233.   register FILE *file1;
  234.   register treasure_type *i_ptr;
  235.  
  236.   prt("Produce objects on what level?: ", 0, 0);
  237.   level = 0;
  238.   if (get_string(tmp_str, 0, 32, 10))
  239.     (void) sscanf(tmp_str, "%d", &level);
  240.   prt("Produce how many objects?: ", 0, 0);
  241.   nobj = 0;
  242.   if (get_string(tmp_str, 0, 27, 10))
  243.     (void) sscanf(tmp_str, "%d", &nobj);
  244.   if ((nobj > 0) && (level > -1) && (level < 1201))
  245.     {
  246.       if (nobj > 9999)
  247.     nobj = 9999;
  248.       prt("File name: ", 0, 0);
  249.       if (get_string(filename1, 0, 11, 64))
  250.     {
  251.       if (strlen(filename1) == 0)
  252.         (void) strcpy(filename1, "MORIAOBJ.DAT");
  253.       if ((file1 = fopen(filename1, "w")) != NULL)
  254.         {
  255.           (void) sprintf(tmp_str, "%d", nobj);
  256.           prt(strcat(tmp_str, " random objects being produced..."), 0, 0);
  257.           put_qio();
  258.           (void) fprintf(file1, "*** Random Object Sampling:\n");
  259.           (void) fprintf(file1, "*** %d objects\n", nobj);
  260.           (void) fprintf(file1, "*** For Level %d\n", level);
  261.           (void) fprintf(file1, "\n");
  262.           (void) fprintf(file1, "\n");
  263.           popt(&j);
  264.           for (i = 0; i < nobj; i++)
  265.         {
  266.           t_list[j] = object_list[get_obj_num(level)];
  267.           magic_treasure(j, level);
  268.           inventory[INVEN_MAX] = t_list[j];
  269.           i_ptr = &inventory[INVEN_MAX];
  270.           unquote(i_ptr->name);
  271.           known1(i_ptr->name);
  272.           known2(i_ptr->name);
  273.           objdes(tmp_str, INVEN_MAX, TRUE);
  274.           (void) fprintf(file1, "%s\n", tmp_str);
  275.         }
  276.           pusht(j);
  277.           (void) fclose(file1);
  278.           prt("Completed.", 0, 0);
  279.         }
  280.       else
  281.         prt("File could not be opened.", 0, 0);
  282.     }
  283.     }
  284. }
  285.  
  286.  
  287. /* Prints a listing of monsters                -RAK-     */
  288. print_monsters()
  289. {
  290.   register int i;
  291.   int j, xpos, attype, adesc;
  292.   register FILE *file1;
  293.   vtype out_val, filename1;
  294.   vtype attstr, attx;
  295.   dtype damstr;
  296.   register creature_type *c_ptr;
  297.   register char *string;
  298.  
  299.   prt("File name: ", 0, 0);
  300.   if (get_string(filename1, 0, 11, 64))
  301.     {
  302.       if (strlen(filename1) == 0)
  303.     (void) strcpy(filename1, "MORIAMON.DAT");
  304.       if ((file1 = fopen(filename1, "w")) != NULL)
  305.     {
  306.       prt("Writing Monster Dictionary...", 0, 0);
  307.       put_qio();
  308.       for (i = 0; i < MAX_CREATURES; i++)
  309.         {
  310.           c_ptr = &c_list[i];
  311.           /* Begin writing to file                                 */
  312.           (void) fprintf(file1, "--------------------------------------------\n");
  313.           (void) strcpy(out_val, c_ptr->name);
  314.           (void) strcat(out_val, "                              ");
  315.           (void) fprintf(file1, "%d  %s     (%c)\n", i, out_val, c_ptr->cchar);
  316.           (void) fprintf(file1, "     Speed ==%d  Level     ==%d  Exp ==%d\n",
  317.               c_ptr->speed, c_ptr->level, (int)c_ptr->mexp);
  318.           (void) fprintf(file1, "     AC    ==%d  Eye-sight ==%d  HD  ==%s\n",
  319.               c_ptr->ac, c_ptr->aaf, c_ptr->hd);
  320.           if (0x80000000 & c_ptr->cmove)
  321.         (void) fprintf(file1, "     Creature is a ***Win Creature***\n");
  322.           if (0x00080000 & c_ptr->cmove)
  323.         (void) fprintf(file1, "     Creature Eats/kills other creatures.\n");
  324.           if (0x0001 & c_ptr->cdefense)
  325.         (void) fprintf(file1, "     Creature is a dragon.\n");
  326.           if (0x0002 & c_ptr->cdefense)
  327.         (void) fprintf(file1, "     Creature is a monster.\n");
  328.           if (0x0004 & c_ptr->cdefense)
  329.         (void) fprintf(file1, "     Creature is evil.\n");
  330.           if (0x0008 & c_ptr->cdefense)
  331.         (void) fprintf(file1, "     Creature is undead.\n");
  332.           if (0x0010 & c_ptr->cdefense)
  333.         (void) fprintf(file1, "     Creature harmed by cold.\n");
  334.           if (0x0020 & c_ptr->cdefense)
  335.         (void) fprintf(file1, "     Creature harmed by fire.\n");
  336.           if (0x0040 & c_ptr->cdefense)
  337.         (void) fprintf(file1, "     Creature harmed by poison.\n");
  338.           if (0x0080 & c_ptr->cdefense)
  339.         (void) fprintf(file1, "     Creature harmed by acid.\n");
  340.           if (0x0100 & c_ptr->cdefense)
  341.         (void) fprintf(file1, "     Creature harmed by blue light.\n");
  342.           if (0x0200 & c_ptr->cdefense)
  343.         (void) fprintf(file1, "     Creature harmed by Stone-to-Mud.\n");
  344.           if (0x1000 & c_ptr->cdefense)
  345.         (void) fprintf(file1, "     Creature cannot be charmed or slept.\n");
  346.           if (0x2000 & c_ptr->cdefense)
  347.         (void) fprintf(file1, "     Creature seen with Infra-Vision.\n");
  348.           if (0x4000 & c_ptr->cdefense)
  349.         (void) fprintf(file1, "     Creature has MAX hit points.\n");
  350.           if (0x00010000 & c_ptr->cmove)
  351.         (void) fprintf(file1, "     Creature is invisible.\n");
  352.           if (0x00100000 & c_ptr->cmove)
  353.         (void) fprintf(file1, "     Creature picks up objects.\n");
  354.           if (0x00200000 & c_ptr->cmove)
  355.         (void) fprintf(file1, "     Creature multiplies.\n");
  356.           if (0x01000000 & c_ptr->cmove)
  357.         (void) fprintf(file1, "     Carries object(s).\n");
  358.           if (0x02000000 & c_ptr->cmove)
  359.         (void) fprintf(file1, "     Carries gold, gems, etc.\n");
  360.           if (0x04000000 & c_ptr->cmove)
  361.         (void) fprintf(file1, "       Has object/gold 60%% of time.\n");
  362.           if (0x08000000 & c_ptr->cmove)
  363.         (void) fprintf(file1, "       Has object/gold 90%% of time.\n");
  364.           if (0x10000000 & c_ptr->cmove)
  365.         (void) fprintf(file1, "       Has 1d2 object(s)/gold.\n");
  366.           if (0x20000000 & c_ptr->cmove)
  367.         (void) fprintf(file1, "       Has 2d2 object(s)/gold.\n");
  368.           if (0x40000000 & c_ptr->cmove)
  369.         (void) fprintf(file1, "       Has 4d2 object(s)/gold.\n");
  370.           /*
  371.            * Creature casts spells / Breathes Dragon
  372.            * breath...
  373.            */
  374.           if (c_ptr->spells != 0)
  375.         {
  376.           (void) fprintf(file1, "   --Spells/Dragon Breath ==\n");
  377.           (void) fprintf(file1, "       Casts spells 1 out of %d turns.\n",
  378.               (int)(0xF & c_ptr->spells));
  379.           if (0x00000010 & c_ptr->spells)
  380.             (void) fprintf(file1, "       Can teleport short.\n");
  381.           if (0x00000020 & c_ptr->spells)
  382.             (void) fprintf(file1, "       Can teleport long.\n");
  383.           if (0x00000040 & c_ptr->spells)
  384.             (void) fprintf(file1, "       Teleport player to itself.\n");
  385.           if (0x00000080 & c_ptr->spells)
  386.             (void) fprintf(file1, "       Cause light wounds.\n");
  387.           if (0x00000100 & c_ptr->spells)
  388.             (void) fprintf(file1, "       Cause serious wounds.\n");
  389.           if (0x00000200 & c_ptr->spells)
  390.             (void) fprintf(file1, "       Hold person.\n");
  391.           if (0x00000400 & c_ptr->spells)
  392.             (void) fprintf(file1, "       Cause blindness.\n");
  393.           if (0x00000800 & c_ptr->spells)
  394.             (void) fprintf(file1, "       Cause confusion.\n");
  395.           if (0x00001000 & c_ptr->spells)
  396.             (void) fprintf(file1, "       Cause fear.\n");
  397.           if (0x00002000 & c_ptr->spells)
  398.             (void) fprintf(file1, "       Summon a monster.\n");
  399.           if (0x00004000 & c_ptr->spells)
  400.             (void) fprintf(file1, "       Summon an undead.\n");
  401.           if (0x00008000 & c_ptr->spells)
  402.             (void) fprintf(file1, "       Slow person.\n");
  403.           if (0x00010000 & c_ptr->spells)
  404.             (void) fprintf(file1, "       Drains mana for healing.\n");
  405.           if (0x00020000 & c_ptr->spells)
  406.             (void) fprintf(file1, "       **Unknown spell value**\n");
  407.           if (0x00040000 & c_ptr->spells)
  408.             (void) fprintf(file1, "       **Unknown spell value**\n");
  409.           if (0x00080000 & c_ptr->spells)
  410.             (void) fprintf(file1, "       Breathes Lightning Dragon Breath.\n");
  411.           if (0x00100000 & c_ptr->spells)
  412.             (void) fprintf(file1, "       Breathes Gas Dragon Breath.\n");
  413.           if (0x00200000 & c_ptr->spells)
  414.             (void) fprintf(file1, "       Breathes Acid Dragon Breath.\n");
  415.           if (0x00400000 & c_ptr->spells)
  416.             (void) fprintf(file1, "       Breathes Frost Dragon Breath.\n");
  417.           if (0x00800000 & c_ptr->spells)
  418.             (void) fprintf(file1, "       Breathes Fire Dragon Breath.\n");
  419.         }
  420.           /* Movement for creature                                 */
  421.           (void) fprintf(file1, "   --Movement ==\n");
  422.           if (0x00000001 & c_ptr->cmove)
  423.         (void) fprintf(file1, "       Move only to attack.\n");
  424.           if (0x00000002 & c_ptr->cmove)
  425.         (void) fprintf(file1, "       Move and attack normally.\n");
  426.           if (0x00000008 & c_ptr->cmove)
  427.         (void) fprintf(file1, "       20%% random movement.\n");
  428.           if (0x00000010 & c_ptr->cmove)
  429.         (void) fprintf(file1, "       40%% random movement.\n");
  430.           if (0x00000020 & c_ptr->cmove)
  431.         (void) fprintf(file1, "       75%% random movement.\n");
  432.           if (0x00020000 & c_ptr->cmove)
  433.         (void) fprintf(file1, "       Can open doors.\n");
  434.           if (0x00040000 & c_ptr->cmove)
  435.         (void) fprintf(file1, "       Can phase through walls.\n");
  436.     
  437.           (void) fprintf(file1, "   --Creature attacks ==\n");
  438.           (void) strcpy(attstr, c_ptr->damage);
  439.           while (strlen(attstr) > 0)
  440.         {
  441.           string = index(attstr, '|');
  442.           if (string)
  443.             xpos = strlen(attstr) - strlen(string);
  444.           else
  445.             xpos = -1;
  446.           if (xpos >= 0)
  447.             {
  448.               (void) strncpy(attx, attstr, xpos);
  449.               attx[xpos] = '\0';
  450.               (void) strcpy(attstr, &attstr[xpos + 1]);
  451.             }
  452.           else
  453.             {
  454.               (void) strcpy(attx, attstr);
  455.               attstr[0] = '\0';
  456.             }
  457.           (void) sscanf(attx, "%d%d%s", &attype, &adesc, damstr);
  458.           out_val[0] = '\0';
  459.           switch (adesc)
  460.             {
  461.             case 1:
  462.               (void) strcpy(out_val, "       Hits for ");
  463.               break;
  464.             case 2:
  465.               (void) strcpy(out_val, "       Bites for ");
  466.               break;
  467.             case 3:
  468.               (void) strcpy(out_val, "       Claws for ");
  469.               break;
  470.             case 4:
  471.               (void) strcpy(out_val, "       Stings for ");
  472.               break;
  473.             case 5:
  474.               (void) strcpy(out_val, "       Touches for ");
  475.               break;
  476.             case 6:
  477.               (void) strcpy(out_val, "       Kicks for ");
  478.               break;
  479.             case 7:
  480.               (void) strcpy(out_val, "       Gazes for ");
  481.               break;
  482.             case 8:
  483.               (void) strcpy(out_val, "       Breathes for ");
  484.               break;
  485.             case 9:
  486.               (void) strcpy(out_val, "       Spits for ");
  487.               break;
  488.             case 10:
  489.               (void) strcpy(out_val, "       Wails for ");
  490.               break;
  491.             case 11:
  492.               (void) strcpy(out_val, "       Embraces for ");
  493.               break;
  494.             case 12:
  495.               (void) strcpy(out_val, "       Crawls on you for ");
  496.               break;
  497.             case 13:
  498.               (void) strcpy(out_val, "       Shoots spores for ");
  499.               break;
  500.             case 14:
  501.               (void) strcpy(out_val, "       Begs for money for ");
  502.               break;
  503.             case 15:
  504.               (void) strcpy(out_val, "       Slimes you for ");
  505.               break;
  506.             case 16:
  507.               (void) strcpy(out_val, "       Crushes you for ");
  508.               break;
  509.             case 17:
  510.               (void) strcpy(out_val, "       Tramples you for ");
  511.               break;
  512.             case 18:
  513.               (void) strcpy(out_val, "       Drools on you for ");
  514.               break;
  515.             case 19:
  516.               (void) strcpy(out_val, "       Insults you for ");
  517.               break;
  518.             case 99:
  519.               (void) strcpy(out_val, "       Is repelled...");
  520.               break;
  521.             default:
  522.               (void) strcpy(out_val, "     **Unknown value** ");
  523.               break;
  524.             }
  525.           switch (attype)
  526.             {
  527.             case 1:
  528.               (void) strcat(out_val, "normal damage.");
  529.               break;
  530.             case 2:
  531.               (void) strcat(out_val, "lowering strength.");
  532.               break;
  533.             case 3:
  534.               (void) strcat(out_val, "confusion.");
  535.               break;
  536.             case 4:
  537.               (void) strcat(out_val, "fear.");
  538.               break;
  539.             case 5:
  540.               (void) strcat(out_val, "fire damage.");
  541.               break;
  542.             case 6:
  543.               (void) strcat(out_val, "acid damage.");
  544.               break;
  545.             case 7:
  546.               (void) strcat(out_val, "cold damage.");
  547.               break;
  548.             case 8:
  549.               (void) strcat(out_val, "lightning damage.");
  550.               break;
  551.             case 9:
  552.               (void) strcat(out_val, "corrosion damage.");
  553.               break;
  554.             case 10:
  555.               (void) strcat(out_val, "blindness.");
  556.               break;
  557.             case 11:
  558.               (void) strcat(out_val, "paralyzation.");
  559.               break;
  560.             case 12:
  561.               (void) strcat(out_val, "stealing money.");
  562.               break;
  563.             case 13:
  564.               (void) strcat(out_val, "stealing object.");
  565.               break;
  566.             case 14:
  567.               (void) strcat(out_val, "poison damage.");
  568.               break;
  569.             case 15:
  570.               (void) strcat(out_val, "lose dexterity.");
  571.               break;
  572.             case 16:
  573.               (void) strcat(out_val, "lose constitution.");
  574.               break;
  575.             case 17:
  576.               (void) strcat(out_val, "lose intelligence.");
  577.               break;
  578.             case 18:
  579.               (void) strcat(out_val, "lose wisdom.");
  580.               break;
  581.             case 19:
  582.               (void) strcat(out_val, "lose experience.");
  583.               break;
  584.             case 20:
  585.               (void) strcat(out_val, "aggravates monsters.");
  586.               break;
  587.             case 21:
  588.               (void) strcat(out_val, "disenchants objects.");
  589.               break;
  590.             case 22:
  591.               (void) strcat(out_val, "eating food.");
  592.               break;
  593.             case 23:
  594.               (void) strcat(out_val, "eating light source.");
  595.               break;
  596.             case 24:
  597.               (void) strcat(out_val, "absorbing charges.");
  598.               break;
  599.             case 99:
  600.               (void) strcat(out_val, "blank message.");
  601.               break;
  602.             default:
  603.               (void) strcat(out_val, "**Unknown value**");
  604.               break;
  605.             }
  606.           (void) fprintf(file1, "%s (%s)\n", out_val, damstr);
  607.         }
  608.           for (j = 0; j < 2; j++)
  609.         (void) fprintf(file1, "\n");
  610.         }
  611.       /* End writing to file                                   */
  612.       (void) fclose(file1);
  613.       prt("Completed.", 0, 0);
  614.     }
  615.     }
  616. }
  617.  
  618.  
  619. /* Print the character to a file or device        -RAK-     */
  620. file_character()
  621. {
  622.   register int i;
  623.   int j, xbth, xbthb, xfos, xsrh, xstl, xdis, xsave, xdev;
  624.   vtype xinfra;
  625.   register FILE *file1;
  626.   vtype out_val, filename1, prt1, prt2;
  627.   stat_type out_str, out_int, out_wis, out_dex, out_con, out_chr;
  628.   register struct misc *p_ptr;
  629.   register treasure_type *i_ptr;
  630.  
  631.   prt("File name: ", 0, 0);
  632.   if (get_string(filename1, 0, 11, 64))
  633.     {
  634.       if (strlen(filename1) == 0)
  635.     (void) strcpy(filename1, "MORIACHR.DAT");
  636.       if ((file1 = fopen(filename1, "w")) != NULL)
  637.     {
  638.       prt("Writing character sheet...", 0, 0);
  639.       put_qio();
  640.       (void) fprintf(file1, "%c", 12);
  641.       cnv_stat(py.stats.cstr, out_str);
  642.       cnv_stat(py.stats.cint, out_int);
  643.       cnv_stat(py.stats.cwis, out_wis);
  644.       cnv_stat(py.stats.cdex, out_dex);
  645.       cnv_stat(py.stats.ccon, out_con);
  646.       cnv_stat(py.stats.cchr, out_chr);
  647.       (void) fprintf(file1, "\n");
  648.       (void) fprintf(file1, "\n");
  649.       (void) fprintf(file1, "\n");
  650.       (void) fprintf(file1, "  Name  :%s", pad(py.misc.name, " ", 25));
  651.       (void) fprintf(file1, "  Age         :%4d", (int)py.misc.age);
  652.       (void) fprintf(file1, "     Strength     :%s\n", out_str);
  653.       (void) fprintf(file1, "  Race  :%s", pad(py.misc.race, " ", 25));
  654.       (void) fprintf(file1, "  Height      :%4d", (int)py.misc.ht);
  655.       (void) fprintf(file1, "     Intelligence :%s\n", out_int);
  656.       (void) fprintf(file1, "  Sex   :%s", pad(py.misc.sex, " ", 25));
  657.       (void) fprintf(file1, "  Weight      :%4d", (int)py.misc.wt);
  658.       (void) fprintf(file1, "     Wisdom       :%s\n", out_wis);
  659.       (void) fprintf(file1, "  Class :%s", pad(py.misc.tclass, " ", 25));
  660.       (void) fprintf(file1, "  Social Class:%4d", py.misc.sc);
  661.       (void) fprintf(file1, "     Dexterity    :%s\n", out_dex);
  662.       (void) fprintf(file1, "  Title :%s", pad(py.misc.title, " ", 25));
  663.       (void) fprintf(file1, "                   ");
  664.       (void) fprintf(file1, "     Constitution :%s\n", out_con);
  665.       (void) fprintf(file1, "                                  ");
  666.       (void) fprintf(file1, "                   ");
  667.       (void) fprintf(file1, "     Charisma     :%s\n", out_chr);
  668.       (void) fprintf(file1, "\n");
  669.       (void) fprintf(file1, "\n");
  670.       (void) fprintf(file1, "\n");
  671.       (void) fprintf(file1, "\n");
  672.     
  673.       (void) fprintf(file1, "  + To Hit    :%6d", py.misc.dis_th);
  674.       (void) fprintf(file1, "     Level      :%6d", (int)py.misc.lev);
  675.       (void) fprintf(file1, "     Max Hit Points :%6d\n", py.misc.mhp);
  676.       (void) fprintf(file1, "  + To Damage :%6d", py.misc.dis_td);
  677.       (void) fprintf(file1, "     Experience :%6d", py.misc.exp);
  678.       (void) fprintf(file1, "     Cur Hit Points :%6d\n", (int) (py.misc.chp));
  679.       (void) fprintf(file1, "  + To AC     :%6d", py.misc.dis_tac);
  680.       (void) fprintf(file1, "     Gold       :%6d", py.misc.au);
  681.       (void) fprintf(file1, "     Max Mana       :%6d\n", py.misc.mana);
  682.       (void) fprintf(file1, "    Total AC  :%6d", py.misc.dis_ac);
  683.       (void) fprintf(file1, "                       ");
  684.       (void) fprintf(file1, "     Cur Mana       :%6d\n", (int) (py.misc.cmana));
  685.     
  686.       (void) fprintf(file1, "\n");
  687.       (void) fprintf(file1, "\n");
  688.       p_ptr = &py.misc;
  689.       xbth = p_ptr->bth + p_ptr->lev * BTH_LEV_ADJ +
  690.         p_ptr->ptohit * BTH_PLUS_ADJ;
  691.       xbthb = p_ptr->bthb + p_ptr->lev * BTH_LEV_ADJ +
  692.         p_ptr->ptohit * BTH_PLUS_ADJ;
  693.       /* this results in a range from 0 to 29 */
  694.       xfos = 40 - p_ptr->fos;
  695.       if (xfos < 0)
  696.         xfos = 0;
  697.       xsrh = p_ptr->srh + int_adj();
  698.       /* this results in a range from 0 to 9 */
  699.       xstl = p_ptr->stl + 1;
  700.       xdis = p_ptr->disarm + p_ptr->lev + 2 * todis_adj() + int_adj();
  701.       xsave = p_ptr->save + p_ptr->lev + wis_adj();
  702.       xdev = p_ptr->save + p_ptr->lev + int_adj();
  703.       (void) sprintf(xinfra, "%d feet", py.flags.see_infra * 10);
  704.  
  705.       (void) fprintf(file1, "(Miscellaneous Abilities)\n");
  706.       (void) fprintf(file1, "\n");
  707.       (void) fprintf(file1, "  Fighting    : %s", pad(likert(xbth, 12), " ", 10));
  708.       (void) fprintf(file1, "  Stealth     : %s", pad(likert(xstl, 1), " ", 10));
  709.       (void) fprintf(file1, "  Perception  : %s\n", pad(likert(xfos, 3), " ", 10));
  710.       (void) fprintf(file1, "  Throw/Bows  : %s", pad(likert(xbthb, 12), " ", 10));
  711.       (void) fprintf(file1, "  Disarming   : %s", pad(likert(xdis, 8), " ", 10));
  712.       (void) fprintf(file1, "  Searching   : %s\n", pad(likert(xsrh, 6), " ", 10));
  713.       (void) fprintf(file1, "  Saving Throw: %s", pad(likert(xsave, 6), " ", 10));
  714.       (void) fprintf(file1, "  Magic Device: %s", pad(likert(xdev, 6), " ", 10));
  715.       (void) fprintf(file1, "  Infra-Vision: %s\n", pad(xinfra, " ", 10));
  716.       /* Write out the character's history     */
  717.       (void) fprintf(file1, "\n");
  718.       (void) fprintf(file1, "\n");
  719.       (void) fprintf(file1, "Character Background\n");
  720.       for (i = 0; i < 5; i++)
  721.         (void) fprintf(file1, "%s\n", pad(py.misc.history[i], " ", 71));
  722.       /* Write out the equipment list...       */
  723.       j = 0;
  724.       (void) fprintf(file1, "\n");
  725.       (void) fprintf(file1, "\n");
  726.       (void) fprintf(file1, "  [Character's Equipment List]\n");
  727.       (void) fprintf(file1, "\n");
  728.       if (equip_ctr == 0)
  729.         (void) fprintf(file1, "  Character has no equipment in use.\n");
  730.       else
  731.         for (i = 22; i < INVEN_MAX; i++)
  732.           {
  733.         i_ptr = &inventory[i];
  734.         if (i_ptr->tval != 0)
  735.           {
  736.             switch (i)
  737.               {
  738.               case 22:
  739.             (void) strcpy(prt1, ") You are wielding   : ");
  740.             break;
  741.               case 23:
  742.             (void) strcpy(prt1, ") Worn on head       : ");
  743.             break;
  744.               case 24:
  745.             (void) strcpy(prt1, ") Worn around neck   : ");
  746.             break;
  747.               case 25:
  748.             (void) strcpy(prt1, ") Worn on body       : ");
  749.             break;
  750.               case 26:
  751.             (void) strcpy(prt1, ") Worn on shield arm : ");
  752.             break;
  753.               case 27:
  754.             (void) strcpy(prt1, ") Worn on hands      : ");
  755.             break;
  756.               case 28:
  757.             (void) strcpy(prt1, ") Right ring finger  : ");
  758.             break;
  759.               case 29:
  760.             (void) strcpy(prt1, ") Left  ring finger  : ");
  761.             break;
  762.               case 30:
  763.             (void) strcpy(prt1, ") Worn on feet       : ");
  764.             break;
  765.               case 31:
  766.             (void) strcpy(prt1, ") Worn about body    : ");
  767.             break;
  768.               case 32:
  769.             (void) strcpy(prt1, ") Light source is    : ");
  770.             break;
  771.               case 33:
  772.             (void) strcpy(prt1, ") Secondary weapon   : ");
  773.             break;
  774.               default:
  775.             (void) strcpy(prt1, ") *Unknown value*    : ");
  776.             break;
  777.               }
  778.             objdes(prt2, i, TRUE);
  779.             (void) sprintf(out_val, "  %c%s%s", j + 97, prt1, prt2);
  780.             (void) fprintf(file1, "%s\n", out_val);
  781.             j++;
  782.           }
  783.           }
  784.     
  785.       /* Write out the character's inventory...        */
  786.       (void) fprintf(file1, "%c", 12);
  787.       (void) fprintf(file1, "\n");
  788.       (void) fprintf(file1, "\n");
  789.       (void) fprintf(file1, "\n");
  790.       (void) fprintf(file1, "  [General Inventory List]\n");
  791.       (void) fprintf(file1, "\n");
  792.       if (inven_ctr == 0)
  793.         (void) fprintf(file1, "  Character has no objects in inventory.\n");
  794.       else
  795.         {
  796.           for (i = 0; i < inven_ctr; i++)
  797.         {
  798.           objdes(prt1, i, TRUE);
  799.           (void) sprintf(out_val, "%c) %s", i + 97, prt1);
  800.           (void) fprintf(file1, "%s\n", out_val);
  801.         }
  802.         }
  803.       (void) fprintf(file1, "%c", 12);
  804.       (void) fclose(file1);
  805.       prt("Completed.", 0, 0);
  806.     }
  807.     }
  808. }
  809.